package genetic.stopCondition;

import genetic.interfaces.Individual;
import genetic.interfaces.Population;
import genetic.interfaces.StopCondition;

public class MarioStopConditionBest<Fitness extends Number & Comparable<Fitness>, I extends Individual<?, ?>> implements StopCondition {

	private Population<I> pop;
	private I best;
	private Integer cont = 0;
	private Integer max;
	
	public MarioStopConditionBest(Population<I> pop, Integer max) {
		this.pop = pop;
		best = pop.getBest();
		this.max = max;
	}
	
	/*
	 * Condição de parada por mudança do melhor.
	 */
	@Override
	public boolean stopCondition() {
		if (best == pop.getBest()) {
			cont++;
		}else{
			cont = 0;
			best = pop.getBest();
		}
		if (cont >= max) {
			return true;
		}
		return false;
	}

}
